﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System. Data.SqlClient;
using System.Data;
using System.Security.Cryptography.X509Certificates;

namespace ConsoleApp1
{
    class Program
    {

        static void Main(string[] args)
        {
            string connectionString = "server=.;database=DBtest;uid=sa;pwd=123456;";
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            sqlConnection.Open();
            var sqlcommandString = "select*from Users";
          
            SqlCommand sqlCommand = new SqlCommand(sqlcommandString, sqlConnection);

            var sdr = sqlCommand.ExecuteReader();
            Console.WriteLine("{0}\t{1}\t{2}\t{3}", "id","用户名","密码","创建时间");
            while (sdr.Read())
            {
                Console.WriteLine("{0}\t{1}\t{3}", sdr["id"], sdr["Username"], sdr["Passward"], sdr["CreatTime"]);
            }
            sqlConnection.Close();
           
            {
                SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlcommandString, connectionString);
                DataTable dataTable = new DataTable();
                dataAdapter.Fill(dataTable);

                Console.WriteLine();

                Console.WriteLine();

                Console.WriteLine();

                Console.WriteLine("{0}\t{1}\t{2}\t{3}", "id", "用户名", "密码", "创建时间");

                for(int i = 0; i < dataTable.Rows.Count; i++) 
                {
                    Console.WriteLine("{0}\t{1}\t{2}\t{3}", dataTable.Rows[i]["id"], dataTable.Rows[i]["Username"],dataTable.Rows[i]["Passward"], dataTable.Rows[i]["CreatTime"]);
                }
            }
                    }
    }
}
